﻿

using Furion.DataValidation;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using IotClientService.Consts;
using IotClientWeb.Models.ZD;
using IotContract.Enums;
using IotContract.Interfaces.Http;
using Microsoft.AspNetCore.Mvc;

namespace IotClientWeb.Controllers;
/// <summary>
/// API服务，对接中鼎机械手等
/// </summary>
[ApiDescriptionSettings(IotApiConst.ZD)]
[Route("eve/restful/api/v3/")]
[NonUnify]
public class ZDService : IDynamicApiController, ITransient
{
    private readonly IClientWebService _webService;
    public ZDService(IClientWebService clientWebService)
    {
        _webService = clientWebService;
    }
    /// <summary>
    /// 机械手在取放物料后数据上报
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [Route("wcs/grab")]
    public async Task<ZdResponse> Grab(GrabRequest request)
    {
        _webService.InvokeValueChangeEvent("Grab");
        Dictionary<string, string> par = new Dictionary<string, string>();
        par.Add("test", "1");
        return new ZdResponse
        {
            Parameters = par

        };
    }
    /// <summary>
    /// 机械手在托盘组盘开始及结束动作时上报
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    [HttpPost]
    [Route("wcs/grabAction")]
    public async Task<ZdResponse> GrabAction(GrabActionRequest request)
    {
        _webService.InvokeValueChangeEvent("GrabAction");
        return new ZdResponse();
    }
    /// <summary>
    /// 电芯到达拉带线扫到码后上报
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    [HttpPost]
    [Route("wcs/materialOnline")]
    public async Task<ReportResponse> MaterialOnline(ReportRequest request)
    {
        _webService.InvokeValueChangeEvent("MaterialOnline");
        return new ReportResponse
        {
            Materials = new List<MaterialStatus>
            {
                new MaterialStatus
                {
                    MaterialCode = "111",
                    MaterialType = "type",
                    StatusCode = "1"
                }
            }
        };
        
    }
    /// <summary>
    /// 电芯出线前扫到码向FMS校验是否允许出线
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    [HttpPost]
    [Route("wcs/materialOfflineCheck")]
    public async Task<ReportResponse> MaterialOfflineCheck(ReportRequest request)
    {
        _webService.InvokeValueChangeEvent("MaterialOfflineCheck");
        return new ReportResponse();
    }
    /// <summary>
    /// 获取组盘信息，拆盘用
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    [HttpPost]
    [Route("wcs/queryAssembleInfo")]
    public async Task<AssembleResponse> QueryAssembleInfo(AssembleRequest request)
    {
        _webService.InvokeValueChangeEvent("QueryAssembleInfo");
        return new AssembleResponse();
    }
    /// <summary>
    /// 用于设备上位机向FMS上报设备状态
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    [HttpPost]
    [Route("device/uploadDeviceStatus")]
    public async Task<ZdInfoResponse> UploadDeviceStatus(ZdStatusRequest request)
    {
        _webService.InvokeValueChangeEvent("QueryAssembleInfo");
        return new ZdInfoResponse();
    }
    /// <summary>
    /// 用于设备上位机向FMS上报设备故障及故障消除信息
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    [HttpPost]
    [Route("device/uploadDeviceError")]
    public async Task<ZdInfoResponse> UploadDeviceError(ZdWarnRequest request)
    {
        _webService.InvokeValueChangeEvent("UploadDeviceError");
        _webService.InvokeWarnEvent(new IotContract.Dtos.Clients.IotEquipWarnDto
        {
            EquipNum = request.EquipNum,
            Data = request.FaultCode,
            ProtobufType=IotProtobufType.WEB_API.ToString()
        });

        return new ZdInfoResponse();
    }
}
